/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commands;

import java.util.Vector;
import javax.swing.DefaultListModel;
import entityclasses.Person;
/**
 *
 * @author YCAN
 */
public class SearchCommander {

    private SearchNameAndLastNameCommand bothSearch;
    private SearchOnlyNameCommand onlyNameSearch;
    private SearchOnlyLastNameCommand onlyLastNameSearch;
    private Vector <Person> specialSearchingVector;
    private DefaultListModel dlm;
    private String currentText;
    
    public SearchCommander(String currentText, Vector <Person> v) {
        dlm = new DefaultListModel();
        this.bothSearch = new SearchNameAndLastNameCommand();
        this.onlyNameSearch = new SearchOnlyNameCommand();
        this.onlyLastNameSearch = new SearchOnlyLastNameCommand();
        this.specialSearchingVector = (Vector<Person>) v;
        this.currentText = currentText;
        
        
        getBothSearchResults();
        getNameSearchResults();
        getLastNameSearchResults();
        
        
    }
    
    public DefaultListModel getBothSearchResults()
    {
        //dlm = new DefaultListModel();
        return bothSearch.execute(dlm,specialSearchingVector,currentText);
    }
    
    public DefaultListModel getNameSearchResults()
    {
        //dlm = new DefaultListModel();
        return onlyNameSearch.execute(dlm,specialSearchingVector,currentText);
    }
    
    public DefaultListModel getLastNameSearchResults()
    {
        //dlm = new DefaultListModel();
        return onlyLastNameSearch.execute(dlm,specialSearchingVector,currentText);
    }
    
    public void distinctModel()
    {
        DefaultListModel dlm2 = new DefaultListModel();
        for(int i=0;i< dlm.getSize();i++)
        {
            for(int j=1;j< dlm.getSize();j++)
            {
                if(dlm.elementAt(i).equals(dlm.elementAt(j)))
                    dlm.remove(j);
            }
        }
    }
    
    public DefaultListModel getResult()
    {
        distinctModel();
        return dlm;
    }
    
    
}
